require(['util', 'validator'], function () {
    var $drvTotScroreForm = $("#drvTotScroreForm");

    var corpId = "",
        seleOrgan = {};

    //左侧树点击事件
    commonFun.leftTreeNodeClickObj['funCheckWeightSet'] = function (event, treeId, treeNode) {
        if (treeNode.type === 'CAR' || treeNode.type === 'DRIVER') {
            $.messager.alert("提示", "请选择组织机构或线路，进行参数设置。", "info");
            return;
        }
        seleOrgan = treeNode;
        corpId = treeNode.corpId;
        $("#u_tip").hide();
        showInterface();
    };

    //根据后台返回的数据，动态生成界面
    var showInterface = function () {
        $.ajaxExt({
            url: "/driverTotalScore/searchDriverTotalScoreInfo.htm",
            data: {"corpId": corpId, "organId": seleOrgan.id}
        }).done(function (data) {
            var currData = data;
            $drvTotScroreForm.empty();
            $("#drvTotScroreBnt").show();

            var flag = 0,
                seleOrganId = seleOrgan.id,
                currOrganId = currData[0].organLineId,
                content = "";
            $drvTotScroreForm.append("<h1 class='line-title'>【" + seleOrgan.name + "】的驾驶员总评分考核权重信息</h1>");
            $drvTotScroreForm.append("<input type='hidden' name='seleDrvOrganId' value='" + seleOrganId + "'/>"
            + "<input type='hidden' name='corpId' value='" + corpId + "'/>"
            + "<input type='hidden' name='currDrvOrganId' value='" + currOrganId + "'/>");
            $.each(currData, function (n, entity) {
                if (flag == 0) {
                    $drvTotScroreForm.append("<div class='user-info-box'>"
                    + "<h2 class='title-style1'><span>" + entity.chkCgyName + "权重</span></h2>"
                    + "<ul id = 'CHK01000' class='form-grid form-grid2 clearfix'>"
                    + "</ul>"
                    + "</div>");
                    flag = 1;
                }
                content = "<li>"
                + "<label class='label-text'>" + entity.chkName + "权重：</label>"
                + "<input type='hidden' name='chkIds' value='" + entity.chkId + "'/>"
                + "<input type='text' name='weightValues' class='input-text length-small' style='width:120px;' data-validator='{required:true,number:true}' value='" + entity.weightValue + "'/> % "
                + "</li>";
                $("#CHK01000").append(content);
            });
        });
    };

    $("#drvTotScrore_update").on("click", function () {
        if ($.validator($('#drvTotScroreForm'))) {
            $.messager.confirm("是否修改", "确定修改该机构所对应的驾驶员考核权重参数？", function (r) {
                if (r) {
                    var formData = $drvTotScroreForm.serialize();
                    $.ajaxExt({
                        url: "/driverTotalScore/uptDriverTotalScoreInfo.htm",
                        data: formData
                    }).done(function (data) {

                    });
                }
            });
        }
    });

    $("#drvTotScrore_reset").on("click", function () {
        showInterface();
    });
    
    //页面打开自动查询
    var nodes = commonFun.getLeftTreeSelectedNodes();
	if(nodes.length<1||nodes[0].type==="LINE"){
		seleOrgan = nodes[0];
        corpId = nodes[0].corpId;
        $("#u_tip").hide();
        showInterface();
	}
})